package com.solarroast.mirrorarray.gui.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.DefaultListModel;

import com.solarroast.mirrorarray.components.MirrorArray;
import com.solarroast.mirrorarray.components.MirrorArraySelection;

public class SaveButtonListener implements ActionListener {
	private MirrorArray mArray;
	private ArrayList<MirrorArraySelection> selections;
	private DefaultListModel model;
	
	public SaveButtonListener(MirrorArray mArray, ArrayList<MirrorArraySelection> selections, DefaultListModel model) {
		this.mArray = mArray;
		this.selections = selections;
		this.model = model;
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(mArray.hasActiveMAIs()) {
			selections.add(new MirrorArraySelection("Selection " + (model.getSize() + 1), mArray.getSelection()));
			model.add(model.getSize(), "Selection " + (model.getSize() + 1));
		}
		else
			System.out.println("Empty selection");
	}
}
